package com.example.server.plugins.routing

import com.example.commons.core.AreaCode
import com.example.commons.core.idcard.IdCardGenerator
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import kotlin.math.max

fun Route.configToolsRouting() {
    route("/tools") {
        get("/genIdcard") {
            val sizeStr = call.request.queryParameters["size"]
            var size = sizeStr?.toIntOrNull() ?: 1
            size = max(size, 1)
            val list = size.downTo(1).map {
                IdCardGenerator.getInstance().generate()
            }
            call.respond(list)
        }
        get("/cityCodes") {
//            val codeJson = ClassLoader.getSystemResourceAsStream("static/id_card_area_code.json")
//            val idcard = Json.decodeFromString(ListSerializer(AreaCode.serializer()), String(codeJson.readBytes()))
            call.respond(AreaCode.areaCodes)
        }
    }
}